<%@ page language="java" pageEncoding="utf-8" %>

<!DOCTYPE html>
<html>
<head>
    <%@include file="../common/base.jsp"%>
	<meta charset="utf-8"/>
	<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1"/>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="Cache-Control" content="no-cache,must-revalidate">
	<meta http-equiv="expires" content="0">
	<title>待支付</title>
	<link rel="stylesheet" type="text/css" href="${base}/css/bootstrap.min.css">
	<link rel="stylesheet" type="text/css" href="${base}/css/global.css?version=${version}">
	<link rel="stylesheet" type="text/css" href="${base}/css/takecar.css?version=${version}">
	<style type="text/css">
		.layui-layer {
			border-radius: 0px !important;
		}
		body{
			position: absolute;
			top: 0;
			right: 0;
			left: 0;
			bottom: 0;
			min-height: 560px;
		}
		.l-footer-wpay{
			position: absolute;
			left: 0;
			right: 0;
			bottom: 15px;
		}
		a.btn-pay:hover,a.btn-pay:active{
			color: #fff;
		}
	</style>
</head>
<body>
<div class="container-fluid">
	<div class="divBox driver-info">
		<%@include file="driverHtml.jsp"%>
		<p class="tip" id="cancelReason">已到达目的地，请支付车费</p>
	</div>
	<%@include file="startEnd.jsp"%>
	<div>
		<div class="paymoney" style="text-align: center;margin-top: 20px">
			<div class="m-totalFare">共<span id="totalFare"></span>元</div>
			<div class="m-totalFare"  ><span id="couponMoney" style="display: none;">券已抵扣<span style="color: #f99359;"></span></span></div>
			<div class="m-totalFare"><div class="m-totalFare m-fareinfo fare-info" href="">查看明细</div></div>
	    </div>

        <%--//TODO 微信支付还没做--%>
        <div class="btn-pay" href="javascript:void(0);">
            去支付
        </div>
    </div>
<div class="l-footer-wpay">
	<%@include file="footer.jsp"%>
</div>
</body>
<script type="text/javascript" src="${base}/js/jquery.min.js"></script>
<script type="text/javascript" src="${base}/plugin/layer-v3.0.3/layer.js"></script>
<script type="text/javascript" src="${base}/js/localStorageOpt.js?version=${version}"></script>
<%--<script type="text/javascript" src="${base}/plugin/crypto-js/crypto-js.min.js"></script>--%>
<%--<script type="text/javascript" src="${base}/plugin/jsencrypt/jsencrypt.min.js"></script>--%>
<script type="text/javascript" src="${base}/js/utils.js?version=${version}"></script>
<script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
<%--<script type="text/javascript" charset="UTF-8" src="https://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>--%>
<script type="text/javascript">
	jQuery(document).ready(function ($) {
        /*用来和选择优惠券的iframe页面进行数据交互使用*/
        //存取，优惠券ID和金额、总金额还有应付金额
        window.couInfo={};
        var typeModule=''
		var $document = $(document);
        var yun=new yueajax( "${openId}");
        var totalFare=0;
        var coupon={};

		$document.on('touchend', '.btn-pay', function () {
            setLocalStorage('couInfo',couInfo);
            layer.open({
                type: 2,
                title: false,
                closeBtn: false,
//            shadeClose: false,
                //skin: 'layui-layer-rim', //加上边框
                area: ['100%', '308px'], //宽高,
                shadeClose: true,
                anim: 'up',
                content: ['/yue/wpay_popup/'+(getLocalStorage('isH5')=="true"? getLocalStorage('yueuserH5','object').uuid : getLocalStorage('yueuserH5','object').uuid ),'no'],
                offset: 'lb',
                success:function(index){
                    index.addClass('notradius')
                }
            });
		});
//    费用详情
        $document.on('touchend', '.m-fareinfo', function () {
            layer.open({
                type: 2,
                title: false,
                closeBtn: false,
                shadeClose: false,
                //skin: 'layui-layer-rim', //加上边框
                area: ['100%', '100%'], //宽高,
//                shadeClose: true,
                anim: 'up',
                content: '${base}/yue/fareInfo?orderUuid='+yun.orderUuid+'&couponFare='+couInfo.couponFare+'&typemodule='+typeModule,
                offset: 'lb',
                success:function(index){
                    index.addClass('notradius')
                }
            });
        });

//选择优惠券
        window.setCouInfo=function(info){
            var i=info;
            if(i==null){//没有传，则不执行
                couInfo.couponUuid = "";
                couInfo.actualFare=couInfo.totalFare;
                couInfo.couponFare =0;
                $('#totalFare').html(couInfo.actualFare)
                $('#couponMoney').find('span').html(couInfo.couponFare)
                return;
            }
            couInfo.couponUuid = i.uuid;
            couInfo.couponFare =(+i.money).toFixed(2);
            couInfo.couponFare=couInfo.couponFare>(+couInfo.totalFare)?(+couInfo.totalFare):couInfo.couponFare;
            couInfo.actualFare= (+couInfo.totalFare)-(couInfo.couponFare);
            couInfo.actualFare=couInfo.actualFare<0?0:couInfo.actualFare;
//            if(info.type==1){//满减券
//                couInfo.couponFare =( i.money>=couInfo.totalFare)?couInfo.totalFare:i.money;
//                couInfo.actualFare= (+couInfo.totalFare)-(+couInfo.couponFare)
//            }else{//折扣券
//                //（1-折扣）*订单总金额：计算出优惠金额
//                couInfo.couponFare=+(((1- i.discount/10)*(couInfo.totalFare)).toFixed(2));
//                //计算优惠后的金额是否超过最高抵扣额
//                couInfo.couponFare=(couInfo.couponFare>= i.highestMoney ? +i.highestMoney : couInfo.couponFare);
//                //计算优惠后金额是否超过总金额
//                couInfo.couponFare=(couInfo.couponFare>= couInfo.totalFare ? couInfo.totalFare : couInfo.couponFare);
//                //计算折扣后费用
//                couInfo.actualFare=couInfo.totalFare - couInfo.couponFare;
//            }
           $('#totalFare').html(couInfo.actualFare)
           $('#couponMoney').find('span').html(couInfo.couponFare)
        }


        //初始化请求订单数据
        getOrderStatus(function (data) {
            //订单创建时间
            var cTime=new Date(data.data.createOn);
            var driver=data.data.driver;
            var cTobj=yun.time_count(cTime)
            var d=data.data;
            $('#faceimg').attr('src',driver.face || '${base}/images/man.png');
			$('.m-fareinfo').data('orderUuid',yun.orderUuid)
            $('#driver_name').html(driver.name);
            $('#driver_score').append(driver.score)
            $('#driver_orderCount').html(driver.orderCount+'单')
            $('#driver_plateNum').html(driver.plateNum)
            $('#driver_carColor_brandName').html(driver.carColor+driver.brandName);
            $('#driver_mobile').attr('href','tel:'+driver.mobile);
            $('#clickCall').attr('href','tel:'+driver.mobile);
            $('#creadtime').html(cTobj.day+'  '+cTobj.hour+cTime.format('hh:mm'));
            $("#originDetailAddressText").html(data.data.originAddress);
            $("#destDetailAddressText").html(data.data.destAddress);
            $('#totalFare').html(data.data.actualFare);
            couInfo={
                actualFare: d.actualFare,
                couponUuid: d.couponUuid || "",
                couponFare: d.couponFare || "",
                totalFare: d.totalFare,
                uuid: d.uuid,
                openid:yun.openId,
                originCityUuid:d.originCityUuid
            }
            typeModule=d.typeModule
            if(!d.couponFare){
                $("#couponMoney").hide()
			}else{
                $("#couponMoney").show();
                $("#couponMoney").find('span').html(d.couponFare || 0);
			}

            if(!!d.cancelReason){$('#cancelReason').html(data.data.cancelReason);}
            if(d.subStatus!=600){
                $('#couponMoney').click(function(){
                    layer.open({
                        type: 2,
                        title: false,
                        closeBtn: false,
                        shadeClose: false,
                        //skin: 'layui-layer-rim', //加上边框
                        area: ['100%', '100%'], //宽高,
                        shadeClose: true,
                        anim: 'up',
                        content: '${base}/yue/coupon?orderUuid='+ couInfo.uuid +'&typeTrip='+d.typeTrip+'&totalFare='+d.totalFare+'&couponUuid='+couInfo.couponUuid+'&originCityUuid='+couInfo.originCityUuid,
                        offset: 'lb'
                    });
                })
			}
        });
        //定时请求OrderDetail，获取订单详情
        var interval = setInterval(getOrderStatus,5000);
		//获取刚才派出的订单ID
		function getOrderStatus(callback) {
            yun.order_ajax(function(data){
                var d=data.data;
                changeUrl(data.data.subStatus,yun.orderUuid);
//                if (d.subStatus != 500) {
////                    changeUrl(data.data.subStatus,yun.orderUuid);
//                }


                //请求司机等待时间和等待费用
                if(typeof callback =="function"){
                    callback(data);
                }

            },function (data) {
                clearInterval(interval)
            })
		}

	});
</script>
</html>
